<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePermissionAndRoles extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //角色表
        Schema::create("admin_roles", function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 30)->default('')->comment("角色名");
            $table->string('description', 100)->default('')->comment("描述");
            $table->integer('created_at')->comment('创建时间');
            $table->integer('updated_at')->comment('修改时间');
        });

        //权限表
        Schema::create("admin_permissions", function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 30)->default('')->comment("角色名");
            $table->string('description', 100)->default('')->comment("描述");
            $table->integer('created_at')->comment('创建时间');
            $table->integer('updated_at')->comment('修改时间');
        });

        //权限角色表
        Schema::create("admin_permission_role", function (Blueprint $table) {
            $table->increments('id');
            $table->integer("role_id")->comment("角色表外键");
            $table->integer("permission_id")->comment("权限表外键");
        });

        //角色用户表
        Schema::create("admin_role_user", function (Blueprint $table) {
            $table->increments('id');
            $table->integer("role_id")->comment("角色表外键");
            $table->integer("user_id")->comment("用户表外键");
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('admin_roles');
        Schema::drop('admin_permissions');
        Schema::drop('admin_permission_role');
        Schema::drop('admin_role_user');
    }
}
